﻿using NFine.WeiXin.Model;
using SqlSugar;
using System;
using System.Linq;

namespace NFine.WeiXin.Service
{
    public class DbContext
    {
        public DbContext()
        {
            Db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = "Server=47.99.80.79;Database=NFine.Framework;User Id=root;Password=flyang.net1234;",
                DbType = DbType.MySql,
                InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息
                IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样我就不多解释了

            });
            //调式代码 用来打印SQL 
            Db.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine(sql + "\r\n" +
                    Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
                Console.WriteLine();
            };
        }
        public SqlSugarClient Db;
        public SimpleClient<WxAccountModel> WxAccountDb { get { return new SimpleClient<WxAccountModel>(Db); } }
        public SimpleClient<WxUserModel> WxUserDb { get { return new SimpleClient<WxUserModel>(Db); } }
    }
}
